<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Add_table_ci_comment extends CI_Migration {

	public function up()
	{
		// Drop table 'comment' if it exists		
		$this->dbforge->drop_table('ci_comment');

		// Table structure for table 'comment'
		$this->dbforge->add_field(array(
			'com_id' => array(
				'type' => 'INT',
				'constraint' => '11',
				'unsigned' => TRUE,
				'auto_increment' => TRUE
			),
		    'com_title' => array(
				'type' => 'VARCHAR',
				'constraint' => '45',
		    ),
		    'com_content' => array(
				'type' => 'TEXT',
			),
			'com_usr_ip' => array(
				'type' => 'VARCHAR',
				'constraint' => '45',
			),
			'com_status' => array(
				'type' => 'TINYINT',
				'constraint' => '1',
			),
			'com_pos_id' => array(
				'type' => 'INT',
				'constraint' => '11',
			),
			'com_parent_id' => array(
				'type' => 'INT',
				'constraint' => '11',
			),
			'com_usr_id' => array(
				'type' => 'MEDIUMINT',
				'constraint' => '8',
			),
			'com_cr_date' => array(
				'type' => 'DATETIME',
			),
			'com_lu_uid' => array(
				'type' => 'INT',
				'constraint' => '11',
			),
			'com_lu_date' => array(
				'type' => 'DATETIME',
			)
			));
		$this->dbforge->add_key('com_id', TRUE);
		$this->dbforge->create_table('ci_comment');


		// Dumping data for table 'groups'
		$data = array(
			array(
				'com_content' => 'ทดสอบ',
				'com_title' => 'ทดสอบ',
			),
		);
		$this->db->insert_batch('ci_comment', $data);


		// Drop table 'images' if it exists
		$this->dbforge->drop_table('ci_images');

		// Table structure for table 'images'
		$this->dbforge->add_field(array(
			'img_id' => array(
				'type' => 'INT',
				'constraint' => '11',
				'unsigned' => TRUE,
				'auto_increment' => TRUE
			),
			'img_filesize' => array(
				'type' => 'VARCHAR',
				'constraint' => '32',
			),
			'img_cr_date' => array(
				'type' => 'DATETIME',
			),
			'img_type' => array(
				'type' => 'VARCHAR',
				'constraint' => '32',
			),
			'img_filename' => array(
				'type' => 'VARCHAR',
				'constraint' => '255',
			),
			'img_filepath' => array(
				'type' => 'VARCHAR',
				'constraint' => '255',
			),
			'img_firstimage' => array(
				'type' => 'TINYINT',
				'constraint' => '1',
			),
			'img_group' => array(
				'type' => 'INT',
				'constraint' => '2',
			),
			'img_fullpath' => array(
				'type' => 'VARCHAR',
				'constraint' => '255',
			),
			'img_large' => array(
				'type' => 'VARCHAR',
				'constraint' => '255',
			),
		   	'img_medium' => array(
				'type' => 'VARCHAR',
				'constraint' => '255',
			),
			'img_small' => array(
				'type' => 'VARCHAR',
				'constraint' => '255',
			),
			'img_pos_id' => array(
				'type' => 'INT',
				'constraint' => '11',
			),
			'img_com_id' => array(
				'type' => 'INT',
				'constraint' => '11',
			)
		));
		$this->dbforge->add_key('img_id', TRUE);
		$this->dbforge->create_table('ci_images');
	}

	public function down()
	{
		$this->dbforge->drop_table('ci_comment');
		$this->dbforge->drop_table('ci_images');

	}
}
